package com.yiwei.ydd.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.ydd.R;
import com.yiwei.ydd.activity.MyMessageActivity;
import com.yiwei.ydd.api.bean.MessageOneTypeBean;
import com.yiwei.ydd.constant.Const;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyMessageTotalAdapter extends ItemAdapter<MessageOneTypeBean, MyMessageTotalAdapter.DefaultHolder> {


    private Context context;

    public MyMessageTotalAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_message_total, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MessageOneTypeBean item = getItem(position);
        switch (item.mesg_type) {
            case Const.MsgType.COMM:
                Glide.with(context).load(R.mipmap.img_msg_type_commission).into(holder.imgIcon);
                holder.txtMsgType.setText("佣金消息");
                break;
            case Const.MsgType.MONEY:
                Glide.with(context).load(R.mipmap.img_msg_type_wallet).into(holder.imgIcon);
                holder.txtMsgType.setText("钱包消息");
                break;
            case Const.MsgType.SYSTEM:
                Glide.with(context).load(R.mipmap.img_msg_type_system).into(holder.imgIcon);
                holder.txtMsgType.setText("系统消息");
                break;
            case Const.MsgType.ORDERS:
                Glide.with(context).load(R.mipmap.img_msg_type_order).into(holder.imgIcon);
                holder.txtMsgType.setText("订单消息");
                break;
        }
        holder.txtMsgContent.setText(item.item);
        holder.txtNum.setText(item.count + "");
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyMessageActivity.class);
                intent.putExtra("type", item.mesg_type);
                context.startActivity(intent);
            }
        });

    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_num)
        SuperButton txtNum;
        @BindView(R.id.txt_msg_type)
        TextView txtMsgType;
        @BindView(R.id.txt_msg_content)
        TextView txtMsgContent;
        @BindView(R.id.txt_msg_time)
        TextView txtMsgTime;
        @BindView(R.id.layout_total)
        RelativeLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
